var layer;
var $;
layui.use(['layedit','laydate','layer','util','table'], function(){
    $=layui.$;
    layer = layui.layer,
        util = layui.util;
    var laydate = layui.laydate;
    var table=layui.table
    //时间插件
    laydate.render({
        elem: '#applyDate', //指定元素
        trigger: 'click' //时间时间为点击事件

    });
    //刷新按钮
    $("#refreshs").on('click',function(){
        window.location.reload();
    })
//返回按钮
    $("#back").on('click',function(){
        history.back(-1);
    })
    //获取审核记录
    getNumber(1,2,3);
    function getNumber(result1,result2,result3){
        $.ajax({
            url:"/personnel/getNumber",//后台路径
            type:"post",
            dataType:"json",
            data:{"result1":result1,"result2":result2,"result3":result3},
            success:function(data){
                $("#value1").html(data.auditNumber);
                $("#value2").html(data.approvedNumber);
                $("#value3").html(data.rejectNumber);
            }
        })
    }

    //待审核 已审核 已驳回
    $("#toAudit").on('click',function(){
        $("#toAudit").removeClass("layui-btn-primary");
        $("#theApproved").addClass("layui-btn-primary");
        $("#beenRejected").addClass("layui-btn-primary");
        $("input[name=result]").val(1);
        SelTab(1);
    })
    $("#theApproved").on('click',function(){
        $("#toAudit").addClass("layui-btn-primary");
        $("#theApproved").removeClass("layui-btn-primary");
        $("#beenRejected").addClass("layui-btn-primary");
        $("input[name=result]").val(2);
        SelTab(2);
    })
    $("#beenRejected").on('click',function(){
        $("#toAudit").addClass("layui-btn-primary");
        $("#theApproved").addClass("layui-btn-primary");
        $("#beenRejected").removeClass("layui-btn-primary");
        $("input[name=result]").val( 3);
        SelTab(3);
    })
    SelTab(1);
    //审核驳回通过表格
    function SelTab(result){
        $.ajax({
            url:"/personnel/SelTab",//后台路径
            type:"post",
            dataType:"json",
            data:{"result":result},
            success:function(data){
                if(result==1){
                    selTable(data.obj);
                }else if(result==2){
                    selTab(data.obj);
                }else if(result==3){
                    seltab(data.obj);
                }

            }
        })
    }

    //高级检索
    $("#jiansuo").on('click',function() {
        layer.open({
            type:2,
            title:"高级检索",
            area:['646px','282px'],
            shade:0,
            content:"/personnel/layer/retrieve_table.html",
            offset:"auto",
            success:function(layero,index){
            }
        })
    })

    selProduct=function(){
        var v =  $("#vil").val();
        var v2 =  $("#vil1").val();
        var v3 = $("#vil2").val();
        var v4 =  $("#vil3").val();
        $.ajax({
            url:"/personnel/SelNumber",
            type:"post",
            dataType:"json",
            data:{"account":v,"phone":v2,"position":v3,"nickname":v4},
            success:function(data){
                selTable(data.obj);
            }
        })
    }

    //查询按钮
    $("#chaxun").on('click',function(){
        var account=$("#accout").val();
        var nickname=$("#nickname").val();
        var applydate=$("#applyDate").val();
        var result=$("result").val();
        obtain(account,nickname,applydate,result);
    })
    function obtain(account,nickname,applydate,result){
        $.ajax({
            url:"/personnel/getTable",//后台路径
            type:"post",
            dataType:"json",
            data:{"account":account,"nickname":nickname,"applyDate":applydate,"result":result},
            success:function(data){
                selTable(data.obj);
            }
        })
    }

    function selTable(data){
        //设备分页table
        table.render({
            elem: "#tab_id",//容器
            data:data,
            title: "数据列表",
            limit: 10,//分页显示条数
            width: 1223,
            page: true,
            toolbar: true,
            cols: [[//定义列
                {type: 'checkbox', fixed: 'left'},//复选框靠左,
                {
                    title: "审核编号", fixed: 'left', align: 'center', width: 120, templet: function (data) {
                        return data.id;
                    }
                },
                {field: "id", hide: true},

                {field: 'nickName', title: "用户昵称", align: 'center', width: 130},
                {
                    field: 'account', title: "用户账号", align: 'center', width: 170, templet: function (data) {
                        return  data.account;
                    }
                },
                {
                    field: 'status', title: '使用/停用', align: 'center', width: 112, templet: function (data) {
                        if (data.status == 2) {
                            return "<input type='checkbox' disabled checked='' name='open' lay-skin='switch' lay-filter='switchTest'>"
                        } else {
                            return "<input type='checkbox'disabled name='close' lay-skin='switch'>"
                        }
                    }
                },
                {field: 'position', title: '申请职位', align: 'center', width: 100},
                {field: 'idCard', title: '身份证', align: 'center', width: 200},
                {field: 'phone', title: '手机号', align: 'center', width: 180},
                {
                    field: "", title: "操作", align: 'center', width: 152, templet: function (data) {

                        return "<a style='color:#009688;cursor:pointer;' onclick='view1(\"" + data.launchId + "\",\""+ data.result+"\");'>查看</a>   " +
                            "<a style='color:#009688;cursor:pointer;' onclick='shenhe(\"" + data.launchId + "\")'>审核</a> ";
                    }
                }
            ]]
        })

    }


    function selTab(data){

        //设备分页table
        table.render({
            elem: "#tab_id",//容器
            data:data,
            title: "数据列表",
            limit: 10,//分页显示条数
            width: 1223,
            page: true,
            toolbar: true,
            cols: [[//定义列
                {type: 'checkbox', fixed: 'left'},//复选框靠左,
                {
                    title: "审核编号", fixed: 'left', align: 'center', width: 120, templet: function (data) {
                        return data.id;
                    }
                },
                {field: "id", hide: true},

                {field: 'nickName', title: "用户昵称", align: 'center', width: 130},
                {
                    field: 'account', title: "用户账号", align: 'center', width: 170, templet: function (data) {
                        return  data.account;
                    }
                },
                {
                    field: 'status', title: '使用/停用', align: 'center', width: 112, templet: function (data) {
                        if (data.status == 2) {
                            return "<input type='checkbox' disabled checked='' name='open' lay-skin='switch' lay-filter='switchTest'>"
                        } else {
                            return "<input type='checkbox'disabled name='close' lay-skin='switch'>"
                        }
                    }
                },
                {field: 'position', title: '申请职位', align: 'center', width: 100},
                {field: 'idCard', title: '身份证', align: 'center', width: 200},
                {field: 'phone', title: '手机号', align: 'center', width: 180},
                {
                    field: "", title: "操作", align: 'center', width: 152, templet: function (data) {
                        return "<a style='color:#009688;cursor:pointer;' onclick='view1(\"" + data.launchId + "\",\""+ data.result+"\");'>查看</a>   " +
                            "<a style='color:#009688;cursor:pointer;' onclick='Review(\"" + data.launchId + "\")'>审核详情</a> ";
                    }
                }
            ]]
        })

    }
    function seltab(data){

        //设备分页table
        table.render({
            elem: "#tab_id",//容器
            data:data,
            title: "数据列表",
            limit: 10,//分页显示条数
            width: 1223,
            page: true,
            toolbar: true,
            cols: [[//定义列
                {type: 'checkbox', fixed: 'left'},//复选框靠左,
                {
                    title: "审核编号", fixed: 'left', align: 'center', width: 120, templet: function (data) {
                        return data.id;
                    }
                },
                {field: "id", hide: true},

                {field: 'nickName', title: "用户昵称", align: 'center', width: 130},
                {
                    field: 'account', title: "用户账号", align: 'center', width: 170, templet: function (data) {
                        return  data.account;
                    }
                },
                {
                    field: 'status', title: '使用/停用', align: 'center', width: 112, templet: function (data) {
                        if (data.status == 2) {
                            return "<input type='checkbox' disabled checked='' name='open' lay-skin='switch' lay-filter='switchTest'>"
                        } else {
                            return "<input type='checkbox'disabled name='close' lay-skin='switch'>"
                        }
                    }
                },
                {field: 'position', title: '申请职位', align: 'center', width: 100},
                {field: 'idCard', title: '身份证', align: 'center', width: 200},
                {field: 'phone', title: '手机号', align: 'center', width: 180},
                {
                    field: "", title: "操作", align: 'center', width: 152, templet: function (data) {
                        return "<a style='color:#009688;cursor:pointer;' onclick='view1(\"" + data.launchId + "\",\""+ data.result+"\");'>查看</a>   " +
                            "<a style='color:#009688;cursor:pointer;' onclick='check(\"" + data.launchId + "\")'>审核详情</a> ";
                    }
                }
            ]]
        })

    }

})
//查看用户详情
function view1(id,result){
    $.ajax({
        url:"/personnel/view",
        type:"post",
        dataType:"json",
        data:{"id":id,"result":result},
        success:function(data){
            devicesMsg(data);
        }
    })
}

//查看详情的弹出设备信息框
function devicesMsg(data){
    layui.use('layer',function(){
        var layer=layui.layer;
        layer.open({
            type:2,//弹出层的类型
            title:"查看详情",
            area:['900px','570px'],//弹出层大小
            shade:0.4,//设置遮罩
            offset: 'auto',
            //弹出层内容
            content:"/personnel/layer/open_table.html",
            success:function(layero,index){
                //查找当前引入的iframe的内容
                var obj = layero.find('iframe').contents();
                obj.find("input[name=accound]").val(data.account);
                obj.find("input[name=nickName]").val(data.nickName);
                obj.find("input[name=userCode]").val(data.userCode);
                obj.find("input[name=realName]").val(data.realName);
                obj.find("input[name=phone]").val(data.phone);
                obj.find("input[name=email]").val(data.email);
                obj.find("input[name=idCard]").val(data.idCard);
                obj.find("input[name=birthDate]").val(data.birthDate);
                obj.find("input[name=freestyle]").val(data.freestyle);
                obj.find("input[name=remarks]").val(data.remarks);
                obj.find("input[name=applyDate]").val(data.applyDate);
                obj.find("input[name=position]").val(data.position);
            }
        })
    })
}


//已通过审核信息
function Review(id){
    $.ajax({
        url:"/personnel/Review",
        type:"post",
        dataType:"json",
        data:{"id":id},
        success:function(data){
            ReviewDetails(data);

        }
    })
}

function ReviewDetails(data){
    layui.use('layer',function(){
        var layer=layui.layer;
        layer.open({
            type:2,//弹出层的类型
            title:"查看详情",
            area:['900px','300px'],//弹出层大小
            shade:0.4,//设置遮罩
            offset: 'auto',
            content:"/personnel/layer/audit_situation.html",
            success:function(layero,index){
                var obj = layero.find('iframe').contents();
                obj.find(".reviewer").text(data.trueName);
                obj.find(".acceptDate").text(data.implementDate);
            }
        })
    })
}

//已驳回的审核信息
function check(id){
    $.ajax({
        url:"/personnel/check",
        type:"post",
        dataType:"json",
        data:{"id":id},
        success:function(data){
            checkDetails(data);
        }
    })
}

function checkDetails(data){
    layui.use('layer',function(){
        var layer=layui.layer;
        layer.open({
            type:2,//弹出层的类型
            title:"查看详情",
            area:['900px','300px'],//弹出层大小
            shade:0.4,//设置遮罩
            offset: 'auto',
            content:"/personnel/layer/check_situation.html",
            success:function(layero,index){
                var obj = layero.find('iframe').contents();
                obj.find(".reviewer").text(data.trueName);
                obj.find(".acceptDate").text(data.implementDate);

            }
        })
    })
}


//审核详情
function shenhe(id){
    $.ajax({
        url:"/personnel/shenhe",
        type:"post",
        dataType:"json",
        data:{"id":id},
        success:function(data){
            audit(data);
        }
    })
}

//审核详情的弹出设备信息框
function audit(data){
    layui.use('layer',function(){
        var layer=layui.layer;
        layer.open({
            type:2,//弹出层的类型
            title:"查看详情",
            area:['1100px','500px'],//弹出层大小
            shade:0.4,//设置遮罩
            offset: 'auto',
            //弹出层内容
            content:"/personnel/layer/audit_table.html",
            success:function(layero,index){
                //查找当前引入的iframe的内容
                var obj = layero.find('iframe').contents();
                obj.find("input[name=accound]").val(data.account);
                obj.find("input[name=nickName]").val(data.nickName);
                obj.find("input[name=userCode]").val(data.userCode);
                obj.find("input[name=realName]").val(data.realName);
                obj.find("input[name=phone]").val(data.phone);
                obj.find("input[name=email]").val(data.email);
                obj.find("input[name=idCard]").val(data.idCard);
                obj.find("input[name=freestyle]").val(data.freestyle);
                obj.find("input[name=remarks]").val(data.remarks);
                obj.find("input[name=applyDate]").val(data.applyDate);
                obj.find("input[name=position]").val(data.position);
                obj.find("input[name=launchId]").val(data.launchId);
            }
        })
    })
}


